home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / documentation / tutorial / example / HighlightArea.java < prev    next >
Encoding:
Java Source  |  1997-07-13  |  3.6 KB  |  110 lines

  1. /*
  2.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. /*
  18.  * @(#)HighlightArea.java    1.2 95/10/13  
  19.  *
  20.  * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
  21.  *
  22.  * Permission to use, copy, modify, and distribute this software
  23.  * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
  24.  * without fee is hereby granted. 
  25.  * Please refer to the file http://java.sun.com/copy_trademarks.html
  26.  * for further important copyright and trademark information and to
  27.  * http://java.sun.com/licensing.html for further important licensing
  28.  * information for the Java (tm) Technology.
  29.  * 
  30.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  31.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  32.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  33.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  34.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  35.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  36.  * 
  37.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  38.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  39.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  40.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  41.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  42.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  43.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  44.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  45.  * HIGH RISK ACTIVITIES.
  46.  */
  47.  
  48. import java.awt.Graphics;
  49. import java.net.URL;
  50. import java.net.MalformedURLException;
  51.  
  52. /**
  53.  * An area highlighting ImageArea class.
  54.  * This class extends the basic ImageArea Class to highlight an area of
  55.  * the base image when the mouse enters the area.
  56.  *
  57.  * @author     Jim Graham
  58.  * @version     1.2, 13 Oct 1995
  59.  */
  60. class HighlightArea extends ImageMapArea {
  61.     int hlmode;
  62.     int hlpercent;
  63.  
  64.     /**
  65.      * The argument string is the highlight mode to be used.
  66.      */
  67.     public void handleArg(String arg) {
  68.     if (arg == null) {
  69.         hlmode = parent.hlmode;
  70.         hlpercent = parent.hlpercent;
  71.     } else {
  72.         if (arg.startsWith("darker")) {
  73.         hlmode = parent.DARKER;
  74.         arg = arg.substring("darker".length());
  75.         } else {
  76.         hlmode = parent.BRIGHTER;
  77.         if (arg.startsWith("brighter")) {
  78.             arg = arg.substring("brighter".length());
  79.         }
  80.         }
  81.         hlpercent = Integer.parseInt(arg);
  82.     }
  83.     }
  84.  
  85.     public void makeImages() {
  86.     setHighlight(parent.getHighlight(X, Y, W, H, hlmode, hlpercent));
  87.     }
  88.  
  89.     public void highlight(Graphics g) {
  90.     if (entered) {
  91.         g.drawImage(hlImage, X, Y, this);
  92.     }
  93.     }
  94.  
  95.     /**
  96.      * The area is repainted when the mouse enters.
  97.      */
  98.     public boolean enter() {
  99.     repaint();
  100.     return true;
  101.     }
  102.  
  103.     /**
  104.      * The area is repainted when the mouse leaves.
  105.      */
  106.     public void exit() {
  107.     repaint();
  108.     }
  109. }
  110.